<?php
/**
 * Class servant à l'affichage, les différentes méthodes renvoient des strings
 * à exploiter dans le framework.
 * @author  Joseph Lemoine - lemoine.joseph@gmail.com
 * @version 1
 */
class Viewer {

    /**
     * Renvois les matériaux requis
     * @author	Joseph Lemoine - lemoine.joseph@gmail.com
     * @param	eveitem	$item	    Objet à décrypter
     * @param	bool	$rowOnly    Si true, ne renvoi que les besoins en composants de base
     * @param	bool	$withPrice  Si true, affiche également les prix de chaque item
     * @return	string
     * @access	public
     */
    public static function showMaterialNeeded($item, $rowOnly = FALSE, $withPrice = FALSE) {
	/* Si on veut le détail */
	if (!$rowOnly)
	    return self::showHeritedNeed($item, $rowOnly, $withPrice);
	/* Sinon si on veut juste les compos de bases */
	else
	    return self::showRawNeed($item, $rowOnly, $withPrice);
    }

    /**
     * Renvois les matériaux requis sous forme d'arboressence
     * @author	Joseph Lemoine - lemoine.joseph@gmail.com
     * @param	eveitem	$item	    Objet à décrypter
     * @param	bool	$rowOnly    Si true, ne renvoi que les besoins en composants de base
     * @param	bool	$withPrice  Si true, affiche également les prix de chaque item
     * @return	string
     * @access	public
     */
    public static function showHeritedNeed($item, $rowOnly, $withPrice) {
	
	/* Affichage de l'invention */
	if (!empty($item->bpo))
	    $send .= "<span>" . self::showInventionMethod($item->bpo) . "</span>";

	/* Ajustement de la quantité requise */
	$qtt = $item->qttRequired
	    + (EveMath::haveToApplyWaste($item->groupID, $item->typeID) ?
	    EveMath::waste($item->parentBPO->carac->me, $item->qttRequired, $item->parentBPO->wasteFactor) : 0);

	/* Affichage de l'item et des quantité requises */
	if (!empty($item->hierarchieLevel)) {
	    
	    $send .= "<tr>"
		. "<td>"
		    . (!empty($item->bpo) ? "<span class='unwrapDetails'>+</span>" : "")
		    . $item->typeName
		. "</td> ";

	    /* Si on affiche depuis le browser in-game */
	    if ($_SERVER["HTTP_EVE_TRUSTED"])
		$send .= "(<button type='button' onclick='CCPEVE.showInfo(" . $item->typeID . ")'>ShowInfo</button>) "
		    . "(<button type='button' onclick='CCPEVE.showMarketDetails(" . $item->typeID . ")'>PriceCheck</button>) ";

	    $send .= (DEBUG ? "<td>(" . $item->typeID . ")</td>" : "")
		    . "<td>" . $qtt . "</td>"
		    . self::showPrice($item)
		. "</tr>";
	}else{
	    $send .= "<span>"
		. "<h4>Cours actuel";

	    /* Si on affiche depuis le browser in-game */
	    if ($_SERVER["HTTP_EVE_TRUSTED"])
		$send .= "(<button type='button' onclick='CCPEVE.showInfo(" . $item->typeID . ")'>ShowInfo</button>) "
			. "(<button type='button' onclick='CCPEVE.showMarketDetails(" . $item->typeID . ")'>PriceCheck</button>) ";

	     $send .= "</h4>";

	    $send .= "<span>" . self::showPrice($item) . "</span>"
		. "</span>";
	}

	/* Détail du BPO le cas échéant */
	if (!empty($item->bpo)){

	    /* Préparation de l'écriture des détails */
	    if (!empty($item->hierarchieLevel)) {
		$send .= "<tr class='wrapedDetails'><td colspan='5'>";
	    } else {
		$send .= "<span>";
	    }

	    $send .= "<h5>Détail du BPO / BPC</h5>"
		. "<span>"
		    . (empty($item->bpo->carac->me) && empty($item->bpo->carac->pe) ? "<b><span style='color:#990088'>Non recherché</span></b> " : "" )
		    . "<form class='MEForm' id='changeBPO" . $item->bpo->blueprintTypeID . "' name='changeBPO" . $item->bpo->blueprintTypeID . "' method='POST' action='?'>"
			. "ME(<input type='text' name='me[" .$item->bpo->blueprintTypeID  . "]' value='" . (INT) $item->bpo->carac->me . "' size='3' />) "
			. "PE (<input type='text' name='pe[" .$item->bpo->blueprintTypeID  . "]' value='" . (INT) $item->bpo->carac->pe . "' size='3' />) "
			. "<input type='submit' value='Modifier' />"
		    . "</form>"
		    . " ME Perfect : " . $item->bpo->bestME
		. "</span>"
		. "<span>"
		    . "<h5>Temps de production</h5>"
		    . "<span>"
			. self::unixToDay($item->productionTime) . "s *" . $qtt
			. " => " . self::unixToDay($item->productionTime * $qtt) . "s = "
			. number_format($item->productionCost, 2) . " ISK"
			. " | rec " . number_format($item->recursiveProdCost(), 2) . " ISK"
		    . "</span>"
		. "</span>";

	    ksort($item->requiredComp);

	    /* Début de liste des composants requis */
	    $send .= "<h5>Objets requis</h5>"
		. "<table class='itemTable'>"
		    . "<tr>
				<th><%KEY_ITEMTABLE_0></th>
				<th><%KEY_ITEMTABLE_1></th>
				<th><%KEY_ITEMTABLE_2></th>
				<th><%KEY_ITEMTABLE_3></th>
				<th><%KEY_ITEMTABLE_4></th>
			</tr>";

	    /* Affichage des compo a travers l'arboressence */
	    foreach($item->requiredComp AS $typeID => $obj){
		/* Appel récursif */
		$send .= self::showMaterialNeeded($obj, $rowOnly, $withPrice);
	    }

	    /* Fermeture du tableau */
	    $send .= "</table>";

	    /* Fin de préparation de l'écriture des détails */
	    if (!empty($item->hierarchieLevel)) {
		$send .= "</td></tr>";
	    } else {
		$send .= "</span>";
	    }
	}

	return $send;
    }

    /**
     * Renvois les matériaux requis sous forme de tableau de composant de base
     * @author	Joseph Lemoine - lemoine.joseph@gmail.com
     * @param	eveitem	$item	    Objet à décrypter
     * @param	bool	$rowOnly    Si true, ne renvoi que les besoins en composants de base
     * @param	bool	$withPrice  Si true, affiche également les prix de chaque item
     * @return	string
     * @access	public
     */
    public static function showRawNeed($item, $rowOnly, $withPrice) {
	/* Affichage de l'item et des quantité requises */
	$send .= "<li>"
		    . "Item : " . $item->marketGroupID . "::<b>" . $item->typeName . "</b>";

	/* Si on affiche depuis le browser in-game */
	if ($_SERVER["HTTP_EVE_TRUSTED"])
	    $send .= "(<button type='button' onclick='CCPEVE.showInfo(" . $item->typeID . ")'>ShowInfo</button>) "
		. "(<button type='button' onclick='CCPEVE.showMarketDetails(" . $item->typeID . ")'>PriceCheck</button>) ";

	$send .= "</li>";

	/* Si on à bien des besoins en compo */
	if (!empty($item->bpo)){
	    /* Récupération des besoins */
	    $list = $item->recursiveNeed();
	    ksort($list);

	    /* Formulaire de débug */
	    if (DEBUG && $withPrice){$send .= "<form name='changePrice' id='changePrice' method='POST' action='?'>";}

	    /* Préparation de la section */
	    $send .= "<ul>";
	    /* Affichage de tout les item requis */
	    foreach($list AS $typeID => $detail){
		$send .= self::showRawDetail($detail, $item, $typeID, $withPrice);
		
		if ($withPrice){
		    $totalBuy += $detail["prix"]->buy * $detail["qtt"];
		    $totalSell += $detail["prix"]->sell * $detail["qtt"];
		}

		$totalVol += $detail["volume"] * $detail["qtt"];
	    }
	    /* Fin de section */
	    $send .= "</ul>";

	    /* Si on réclame l'affichage du prix */
	    if ($withPrice)
		$send .= "_____________________________________<br />"
		    . "Total hors invention : " . number_format($totalBuy, 2)
		    . " jita("
		    . ($withPrice ? number_format($item->price->buy, 2) : "")
		    . ")<br />"
		    . "Total hors invention : " . number_format($totalSell, 2)
		    . " jita("
		    . ($withPrice ? number_format($item->price->sell, 2) : "")
		    . ")<br />"
		    . "Volume de transport : " . number_format($totalVol, 2)
		    . "<br />";
	    
	    /* Formulaire de débug */
	    if (DEBUG && $withPrice){$send .= "</form>";}

	    /**
	     * Affichage des raw directes sortie de BPO 
	     */

	    /* Récupération des besoins */
	    $list = $item->basicNeed();
	    ksort($list);

	    /* Initialisation de la somme des prix */
	    $totalBuy = 0;
	    $totalSell = 0;
	    $totalVol = 0;

	    /* Préparation de la section */
	    $send .= "<ul>";
	    /* Affichage de tout les item requis */
	    foreach($list AS $typeID => $detail){
		$send .= self::showRawDetail($detail, $item, $typeID, $withPrice);

		if ($withPrice){
		    $totalBuy += $detail["prix"]->buy * $detail["qtt"];
		    $totalSell += $detail["prix"]->sell * $detail["qtt"];
		}

		$totalVol += $detail["volume"] * $detail["qtt"];
	    }
	    /* Fin de section */
	    $send .= "</ul>";

	    /* Si on réclame l'affichage du prix */
	    if ($withPrice)
		$send .= "_____________________________________<br />"
		    . "Total hors invention : " . number_format($totalBuy, 2)
		    . " jita("
		    . ($withPrice ? number_format($item->price->buy, 2) : "")
		    . ")<br />"
		    . "Total hors invention : " . number_format($totalSell, 2)
		    . " jita("
		    . ($withPrice ? number_format($item->price->sell, 2) : "")
		    . ")<br />"
		    . "Volume de transport : " . number_format($totalVol, 2)
		    . "<br />";

	    return $send;
	}else
	    return FALSE;
    }

    private static function showRawDetail($detail, $item, $typeID, $withPrice) {
	$send .= "<li>"
		. "<b>" . $detail["nom"] . "</b> (" . $typeID . ") *" . $detail["qtt"] . " "
		. ($withPrice ? " => " . $detail["prix"]->buy . " *" . $detail["qtt"] . " (run = " . $item->portionSize . "u) = "
		    . number_format(($detail["prix"]->buy * $detail["qtt"]), 2) : "")
		. (DEBUG && $withPrice?
		    " | <input type='text'
			id='changePriceOf[" . $typeID . "]'
			name='changePriceOf[" . $typeID . "]'
			value='" . $detail["prix"]->buy . "'
		    />"
		    : ""
		) // Formulaire pour débug rapide
		. " [Vol : " . number_format($detail["volume"] * $detail["qtt"], 2) . "]"
	    . "</li>";

	return $send;
    }

    /**
     * Renvoit un string contenant le prix
     * @author	Joseph Lemoine - lemoine.joseph@gmail.com
     * @param	eveitem	    Objet eveitem chargé
     * @return	string
     * @access	public
     */
    public static function showPrice($item) {
	/* Alias */
	$typeID = $item->typeID;
	$prisJita = $item->price->buy;
	$qtt = $item->qttRequired
	    + (EveMath::haveToApplyWaste($item->groupID, $item->typeID) ?
	    EveMath::waste($item->parentBPO->carac->me, $item->qttRequired, $item->parentBPO->wasteFactor) : 0);

	/* Le prix de prod est calculé avec la quantité requise */
	$prixProd = (!empty($item->bpo) ? ($item->recursivePrice() + $item->recursiveProdCost())/ $item->portionSize : 0);

	if (!empty($item->hierarchieLevel)){
	    /* Si le prix jita est plus intéressant */
	    if($prisJita < $prixProd || empty($prixProd)){

		$send .= "<td>" . number_format($prisJita, 2) . "</td>"
		    . "<td>" . number_format(($prisJita * $qtt), 2) . "</td>"
		    . "<td>Jita</td>";

	    } else {

		$send .= "<td>" . number_format($prixProd, 2) . "</td>"
		    . "<td>" . number_format(($prixProd * $qtt), 2) . "</td>"
		    . "<td>Interne</td>";
		
	    }
	}
	
	/* Ecriture de la chaine à renvoyer */
	if (!empty($item->bpo)) {
	    /* Calcul du cout des installations */
	    $prixInstall = (!empty($item->bpo) ? $item->recursiveProdCost() / $item->portionSize : 0);
	    
	    /* Si cet item s'invente */
	    if(!empty($item->bpo->inventionChance))
		/* On multiplie par $qtt car les chiffres sont données par unitées */
		$prixInvention = (
			(
			    (
				$item->bpo->inventionTryCost
				/ $item->bpo->inventionChance
			    )
			    / $item->bpo->baseRun
			)
			/ $item->portionSize
		    ) * $qtt;

	    $prixTotal = $prixProd + $prixInvention + $prixInstall;
	    
	    $send .= "</tr>"
		. "<tr class='wrapedDetails'>"
		    . "<td colspan='5'>"
			. "<h5>Détail du marché pour " . $item->typeName . "</h5>"
			. "<table class='priceTable'>"
			    . "<tr>"
				. "<th>Type</th>"
				. "<th>Prix</th>"
				. "<th>qtt</th>"
				. "<th>Total</th>"
				. "<th>%</th>"
				. "<th>$</th>"
			    . "</tr>"
			    . "<tr>"
				. "<td>Jita SO</td>"
				. "<td>" . number_format($item->price->sell, 2) . "</td>"
				. "<td>" . $qtt . "</td>"
				. "<td>" . number_format(($item->price->sell * $qtt), 2) . "</td>"
				. "<td>" . number_format(($item->price->sell / ($prixTotal / $qtt) - 1) * 100, 2) . "</td>"
				. "<td>" . number_format($item->price->sell * $qtt - $prixTotal, 2) . "</td>"
			    . "</tr>"
			    . "<tr>"
				. "<td>Jita BO</td>"
				. "<td>" . number_format($item->price->buy, 2) . "</td>"
				. "<td>" . $qtt . "</td>"
				. "<td>" . number_format(($item->price->buy * $qtt), 2) . "</td>"
				. "<td>" . number_format(($item->price->buy / ($prixTotal / $qtt) - 1) * 100, 2) . "</td>"
				. "<td>" . number_format($item->price->buy * $qtt - $prixTotal, 2) . "</td>"
			    . "</tr>"
			    . "<tr>"
				. "<td>Prix ICE</td>"
				. "<td>" . number_format(($prixProd + $prixInvention + $prixInstall) / $qtt, 2) . "</td>"
				. "<td>" . $qtt . "</td>"
				. "<td>" . number_format(($prixProd + $prixInvention + $prixInstall), 2) . "</td>"
				. "<td>N/A</td>"
				. "<td>N/A</td>"
			    . "</tr>"
			. "</table>"
		    . "</td>"
		. "</tr>"
		. "<tr class='wrapedDetails'>"
		    . "<td colspan='5'>"
			. "<h5>Détail des couts de productions d'une unité</h5>"
			. "<table class='priceTable'>"
			    . "<tr>"
				. "<th>Composants</th>"
				. "<th>Invention</th>"
				. "<th>Manufacture</th>"
				. "<th>Recherche</th>"
				. "<th>Copie</th>"
				. "<th>Volume</th>"
			    . "</tr>"
			    . "<tr>"
				. "<td>" . number_format($prixProd, 2) . "</td>"
				. "<td>" . number_format($prixInvention, 2) . "</td>"
				. "<td>" . number_format($prixInstall, 2) . "</td>"
				. "<td>Recherche</td>"
				. "<td>Copie</td>"
				. "<td>" . number_format($item->recursiveVolume(), 2) . "</td>"
			    . "</tr>"
			. "</table>"
		    . "</td>"
		. "</tr>";
	}
	return $send;
    }

    /**
     * Affiche la méthode d'invention à utiliser avec le BPO T1 de l'item T2
     * @author	Joseph Lemoine - lemoine.joseph@gmail.com
     * @param	EveBPO	    Objet EveBPO chargé
     * @return	string
     * @access	public
     */
    public static function showInventionMethod($bpo) {
	/* Si ce BPO peut-être inventé (si il possède des items activity 8) */
	if ($bpo->requiredComp(8, 0, 1)) {
	    
	    $send = "<h4>Invention du BPC de " . $bpo->parent->typeName . " :</h4>";

	    /* Affichage des datacores */
	    $send .= "<span>"
		. "<h5>Objets requis</h5>"
		. "<table class='itemTable'>"
		    . "<tr><node::th*5><%KEY_ITEMTABLE@%></node::th></tr>";

	    /* Affichage des besoins en datacore et interface */
	    foreach($bpo->requiredDC AS $typeID => $item){
		$send .= self::showMaterialNeeded($item);
	    }

	    /* Affichage du decryptor */
	    $send .= "<tr>"
		    . "<th>Decryptor</th>"
		    . "<th>Cout total</th>"
		    . "<th>ME</th>"
		    . "<th>PE</th>"
		    . "<th>Nb runs</th>"
		. "</tr>";
	    if (!empty($bpo->bestInvDecryptor))
		$send .= "<tr>"
			. "<td>" . $bpo->bestInvDecryptor["name"] . "</td>"
			. "<td>" . number_format($bpo->bestInvRatio, 2) . "</td>"
			. "<td>" . $bpo->carac->me . "</td>"
			. "<td>" . $bpo->carac->pe . "</td>"
			. "<td>" . $bpo->baseRun . "</td>"
		    . "</tr>";
	    else
		$send .= "<tr>"
			. "<td>Sans decryptor</td>"
			. "<td>" . number_format($bpo->bestInvRatio, 2) . "</td>"
			. "<td>" . $bpo->carac->me . "</td>"
			. "<td>" . $bpo->carac->pe . "</td>"
			. "<td>" . $bpo->baseRun . "</td>"
		    . "</tr>";

	    /* Affichage du meta item */
	    $send .= "<tr>"
		    . "<th>Meta item</th>"
		    . "<th>Meta level</th>"
		    . "<th>Cout</th>"
		    . "<th>Cout</th>"
		    . "<th>Cout</th>"
		. "</tr>";
	    if (!empty($bpo->bestInvMeta))
		$send .= "<tr>"
			. "<td>" . $bpo->bestInvMeta["typeName"] . "</td>"
			. "<td>" . $bpo->bestInvMeta["metaLevel"] . "</td>"
			. "<td>CUIR</td>"
			. "<td>CUIR</td>"
			. "<td>CUIR</td>"
		    . "</tr>";
	    else
		$send .= "<tr>"
			. "<td>Sans item</td>"
			. "<td>CUIR</td>"
			. "<td>CUIR</td>"
			. "<td>CUIR</td>"
			. "<td>CUIR</td>"
		    . "</tr>";
	    
	    $send .= "</table>"
		. "</span>";

	    /* Affichage du prix résumant l'invention */
	    $pratique = new IcuInvStats($bpo->blueprintTypeID);
	    $prix = ($bpo->inventionTryCost / $bpo->inventionChance);
	    $send .= "<span>"
		    . "<h5>Prix de l'invention</h5>"
		    . "<table class='priceTable'>"
			. "<tr>" 
			    . "<th>Réussite (" . ENCRSKILL . "/" . SKILLA . "/" . SKILLA . ")</th>"
			    . "<th>nb essais</th>"
			    . "<th>ISK / tentative</th>"
			    . "<th>ISK / Moyenne</th>"
			    . "<th>ISK / run</th>"
			    . "<th>ISK / Unité</th>"
			. "</tr>"
			. "<tr>"
			    . "<td>" . (INT) ($bpo->inventionChance * 100) . "</td>"
			    . "<td>" . number_format(1/$bpo->inventionChance, 2) . "</td>"
			    . "<td>" . number_format($bpo->inventionTryCost, 2) . "</td>"
			    . "<td>" . number_format($prix, 2) . "</td>"
			    . "<td>" . number_format($prix / $bpo->baseRun, 2) . "</td>"
			    . "<td>" . number_format((($prix / $bpo->baseRun )/ $bpo->parent->portionSize), 2) . "</td>"
			. "</tr>"
		    . "</table>"
		. "</span>"
		. "<span>"
		    . "<h5>Résultats en pratique</h5>"
		    . "<form action='?typeID=" . (INT) $_GET["typeID"] . "' method='POST' name='changeInvStats'>"
			. "<table class='priceTable'>"
			    . "<tr>"
				. "<node::th*4><%KEY_INV_PRACTICE@%></node::th>"
			    . "</tr>"
			    . "<tr>"
				. "<td>" . number_format($pratique->TrySum(), 0) . "</td>"
				. "<td>" . number_format($pratique->nbSuccess, 0) . "</td>"
				. "<td>" . number_format($pratique->nbFails, 0) . "</td>"
				. "<td>" . number_format($pratique->successRatio(), 2) . "</td>"
			    . "</tr>"
			    . "<tr>"
				. "<td>Ajouter une nouvelle tentative</td>"
				. "<td><input type='radio' name='invention' value='success' id='success' /></td>"
				. "<td><input type='radio' name='invention' value='fail' id='fail' /></td>"
				. "<td><input type='submit' class='submitSwitch' value='Ajouter' /></td>"
			    . "</tr>"
			. "</table>"
		    . "</form>"
		. "</span>";
	}

	return $send;
    }
    
    /**
     * Renvoit une chaine composé de tout les menu et sous menu du marché
     * @author	Joseph Lemoine - lemoine.joseph@gmail.com
     * @param	evemarket   $market	Objet evemarket chargé
     * @return	string			Arboressence complète du menu et ses sous menu
     * @access	public
     */
    public static function showMarket($market) {
	/* Si le fichier est en cache */
	if (file_exists(CACHEPATH . "marketMenu-" . $market->marketGroupID . ".htm")) {

	    /* On renvoit le cache avec file_get_contents, on s'emmerde pas */
	    $send = file_get_contents(CACHEPATH . "marketMenu-" . $market->marketGroupID . ".htm");

	} else {
	    
	    /* Sinon on créer l'arboressence (adieu proco, ram, chèvres etc ...) */
	    $send = self::recursiveMarket($market);

	    /* Mise en cache du bouzin */
	    file_put_contents(CACHEPATH . "marketMenu-" . $market->marketGroupID . ".htm", $send);
	}

	return $send;
    }

    /**
     * Affiche de façon récursive le menu market
     * @author	Joseph Lemoine - lemoine.joseph@gmail.com
     * @param	EveMarket   $market	Objet market
     * @return	string			Arboressence complète
     * @access	private
     */
    private static function recursiveMarket($market) {
	/* Si ce n'est pas une fin d'arboressence */
	if (!$market->hasTypes || !empty($market->itemList)){
	    $send .= "<li class='" . ($market->marketGroupName == MARKETROOTNAME ? "marketMenu" : "toggleSubMenu") . "'>"
		    . "<span>"
			. $market->marketGroupName
			. (DEBUG ? " (" . $market->marketGroupID . ")" : "")
		    . "</span>"
		    . "<ul class='" . ($market->marketGroupName == MARKETROOTNAME ? "navigation" : "subMenu") . "'>";

	    if (!empty($market->subGroup))
		foreach($market->subGroup AS $marketID => $child)
		    $send .= self::recursiveMarket($child);
	    else
		foreach($market->itemList AS $typeID => $typeName)
		    $send .= "<li>"
			    . "<a href='?typeID=" . $typeID . "'>"
				. $typeName
			    . "</a>"
			. "</li>";

	    $send .= "</ul></li>";
	} else {
	    $send .= "<li class='" . (empty($market->itemList) ? "" : "toggleSubMenu") . "'>"
		    . "<a href='javascript:getItemList(" . $market->marketGroupID . ");'>"
			. $market->marketGroupName
			. (DEBUG ? " (" . $market->marketGroupID . ")" : "")
		    . "</a>"
		    . "<ul class='subMenu' id='receipValOf" . $market->marketGroupID . "'></ul>"
		. "</li>";
	}
	
	return $send;
    }

    /**
     * Fonction d'affichage des items d'un menu du market
     * @author	Joseph Lemoine - lemoine.joseph@gmail.com
     * @param	EveMarket   $market	Objet où chercher les items
     * @return	string			Liste des objets concernés
     * @access	public
     */
    public static function ShowMarketItem($market) {
	if (!empty($market->itemList)){
	    foreach($market->itemList AS $typeID => $typeName)
		$send .= "<li>"
			. "<a href='?typeID=" . $typeID . "'>"
			    . $typeName
			. "</a>"
		    . "</li>";
	    
	    return $send;
	}else
	    return FALSE;
    }

    public static function unixToDay($timestamp) {

	$minutes = $timestamp%3600;
	
	$heure = floor($timestamp/3600);

	$jour = floor($heure/24);

	$heure -= $jour * 24;

	if($heure < 10)
		$heure = "0" . $heure;
	if($jour < 10 && !empty($jour))
		$jour = "0" . $jour;

	$send .= (!empty($jour) ? $jour . "j " : "") . $heure . ":" . date("i:s",mktime(0,0,$minutes,0,0,0));

	return $send;
    }
}
?>
